package com.dudu.service.impl;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import net.sf.json.JSONObject;

import com.dudu.dao.SmsInfoDetailDao;
import com.dudu.enumeration.AbilityTypeEnum;
import com.dudu.service.ISmsInfoDetailService;

import core.CoreDao;
import core.CoreDaoInvoke;
import core.util.DateUtil;

public class SmsInfoDetailServiceImpl implements ISmsInfoDetailService {
	private CoreDao coreDao = CoreDaoInvoke.getInstance();
	private SmsInfoDetailDao smsdao=new SmsInfoDetailDao();
	/**
	 * 查询条数（分页用）
	 * @param paramSql
	 * @return
	 */
	public Integer getTotalAcount(String paramSql){
		return smsdao.getTotalAcount(coreDao,paramSql);
	}
	
	
	/**
	 * 查询数据（分页）
	 * @param paramSql
	 * @param pageSql
	 * @return
	 */
	public List<JSONObject> queryAll(String paramSql,String pageSql){
		List<JSONObject> list=smsdao.queryAll(coreDao,paramSql,pageSql);
		if(null==list){
			return list;
		}
		for(JSONObject object:list){
			JSONObject create_time=object.getJSONObject("send_time");
			Long time=create_time.getLong("time");
			Date cDate=new Date(time);
			object.put("send_time", DateUtil.parseDate(cDate));
			String ability_type=object.optString("ability_type");
			String ability_typevalue=AbilityTypeEnum.getAbilityTypeEnum(ability_type).getValue();
			if(StringUtils.isBlank(ability_typevalue)){
			    object.put("ability_type", ability_type);
			}else{
			    object.put("ability_type", ability_typevalue);
			}
			
		}
		return list;
	}


	/**
	 * 查询条数（分页用）
	 * @param paramSql
	 * @return
	 */
	public Integer getTotalUpstream(String paramSql) {
		return smsdao.getTotalUpstream(coreDao,paramSql);
	}


	/**
	 * 查询数据（分页）
	 * @param paramSql
	 * @param pageSql
	 * @return
	 */
	public List<JSONObject> queryAllUpstreamList(String paramSql, String pageSql) {
		List<JSONObject> list=smsdao.queryAllUpstreamList(coreDao,paramSql,pageSql);
		if(null==list){
			return list;
		}
		return list;
	}
}
